/*
 * @Description: 
 * @Author: 
 * @Date: 2022-03-24 08:46:34
 * @LastEditTime: 2022-04-06 16:15:38
 */
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import AutoImport from 'unplugin-auto-import/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import { defineConfig } from 'vite';
// import ViteRequireContext from '@originjs/vite-plugin-require-context'
import { createSvg } from './src/icons/index';
import px2rem from 'postcss-plugin-px2rem'
const px2remOptions = {
  rootValue: 19.2,
  unitPercision: 5,
  mediaQuery: false,
  minPixelValue: 0
}
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver({importStyle:'sass'})],
      dts: './auto-imports.d.ts', // 生成 `auto-import.d.ts` 全局声明
      eslintrc: {//自动导入依赖，eslint默认会报错，在此配置
        enabled: true, // Default `false`
        filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
        globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
      },
      imports: [
        'vue',
        'vue-router',
      ]
    }),
    Components({
      dirs: ['src/components/'],
      resolvers: [ElementPlusResolver({
        importStyle: "sass"
      })],
      dts: './components.d.ts'
    }),
    // ViteRequireContext(
    //     /* options */
    // ),
    createSvg('./src/icons/svg/')
  ],
  resolve: {
    alias: {
      '@': resolve(`./src`),
      'src': resolve(`./src`),
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/assets/scss/mixin.scss" as *;`
      }
    },
    postcss: {
      plugins: [px2rem(px2remOptions)]
    }
  },
  base:`./`,
  build: {
    sourcemap: false, //是否生成 source map 文件
    chunkSizeWarningLimit: 800, //chunk 大小警告的限制（以 kbs 为单位）。
    rollupOptions:{
      output: {
        manualChunks(id) {
          console.log(id)
          if (id.includes('node_modules')) {
            return id.toString().split('node_modules/')[1].split(`/`)[0].toString()
          }
        }
      }
    }
  },
  server: {
    open: false,
    host: '0.0.0.0',
    port: 3003,
    proxy: {
      // '/appspace': 'http://192.168.1.210:8001'
      '/appspace': 'http://192.168.1.239:8002',
      // '/appspace': 'http://192.168.47.22:8002'
      '/digital-assert':'http://assets.server.com'
      // '/se-auth': 'http://101.200.182.168:44412/'
    }
  },
});
